package com.js.data.dtmg;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;

import java.util.Collections;

/**
 * Oracle 代码生成
 *
 * @author lanjerry
 * @since 3.5.3
 */
public class GenCode {
    /**
     * 策略配置
     */
    protected static StrategyConfig.Builder strategyConfig() {
        return new StrategyConfig.Builder();
    }

    /**
     * 全局配置
     */
    protected static GlobalConfig.Builder globalConfig() {
        return new GlobalConfig.Builder();
    }

    /**
     * 包配置
     */
    protected static PackageConfig.Builder packageConfig() {
        return new PackageConfig.Builder();
    }

    /**
     * 模板配置
     */
    protected static TemplateConfig.Builder templateConfig() {
        return new TemplateConfig.Builder();
    }

    /**
     * 注入配置
     */
    protected static InjectionConfig.Builder injectionConfig() {
        // 测试自定义输出文件之前注入操作，该操作再执行生成代码前 debug 查看
        return new InjectionConfig.Builder().beforeOutputFile((tableInfo, objectMap) -> {
            System.out.println("tableInfo: " + tableInfo.getEntityName() + " objectMap: " + objectMap.size());
        });
    }
    /**
     * 数据源配置
     */
    private static final DataSourceConfig DATA_SOURCE_CONFIG = new DataSourceConfig
            .Builder("jdbc:mysql://127.0.0.1:3306/data_manage?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false", "root", "root")
            .build();

    public static void main(String[] args) {
        String moduleName = "dtmg";
        AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
        String path = System.getProperty("user.dir");
        generator.global(globalConfig().author("hh").outputDir(path+"\\src\\main\\java").build());
        generator.packageInfo(packageConfig().parent("com.js.data").moduleName(moduleName)
                .pathInfo(Collections.singletonMap(OutputFile.mapperXml,path+"\\src\\main\\resources\\mapper\\"+moduleName+"\\"))
                .build());

        StrategyConfig  config = strategyConfig()
                 //数据库表
                .addInclude("dt_crontab_log")
                .entityBuilder()
                .superClass("com.js.data.common.entity.BasePlusEntity").addSuperEntityColumns( "update_time", "update_by", "create_time", "create_by", "del_flag")
                .enableLombok()
                .build();

        generator.strategy(config);
        generator.execute();

    }


}
